package com.voice.server.observer.impl;

import com.voice.server.command.MessageCommand;
import com.voice.server.enums.PushTypeEnum;
import com.voice.server.observer.Observable;
import com.voice.server.observer.Observer;
import com.wangjiacai.utils.utils.EnumUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class SdkObserver implements Observer {

    @Autowired
    private Map<String, MessageCommand > commandMap;

    @Override
    public void update(Observable observable, String userId, String deviceKey, Object data, Object... param) {
        Integer pushType= (Integer) param[0];
        if(pushType==null) pushType=PushTypeEnum.Text.getCode();
        PushTypeEnum pushTypeEnum=EnumUtil.getEnumByCode(pushType,PushTypeEnum.class);
        MessageCommand command=commandMap.get(pushTypeEnum.getKey());
        command.executeSdk(userId,deviceKey,data);
    }

}
